<template>
  <button 
    :class="classes + ' buttonSty ' + state + (disabled ? ' disabled' : '')" 
    @tap.stop="clickHandler"
    @getphonenumber="$emit('getphonenumber', $event)"
    :open-type="open_type">
    <text class="anim" />
    <slot>微信一键登录</slot>
  </button>
</template>

<script>
  /* 
  自定义按钮：点击会有涟漪效果
  */
  export default {
    props: {
      disabled: { // 按钮处于禁用状态
        type: Boolean,
        default: false
      },
      classes: { // 按钮类名
        type: String
      },
      open_type: { // 按钮的开放能力
        type: String
      }
    },
    data() {
      return {
        state: '',
      }
    },
    methods: {
      clickHandler (e) {
        if (this.disabled) {
          return
        }
        this.$emit('tap', e)
        let state = this.state
        if (state == 'checked') {
          this.state ='nochecked'
        } else {
          this.state = 'checked'
        }
      }
    }
  }
</script>

<style>
  .buttonSty {
    position: relative;
    margin-top: 30upx;
    display: inline-block;
    padding: 0upx 90upx;
    text-align: center;
    border-radius: 5px;
    overflow: hidden;
    position: relative;
    z-index: 2;
    letter-spacing: 3upx;
    font-size: 30upx;
    font-family: Helvetica;
    outline:none;
    border:none;
    /* transition: background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,border 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; */
  }
  button::after {
    outline:none;
    border:none;
  }
  /*动画元素*/
  .anim {
    transform: translateY(-50%) translateX(-50%);
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: -1;
  }
  
  /*目的是保持after能和anim保持一样大小*/
  .anim:before {
    position: relative;
    content: '';
    display: block;
    margin-top: 100%;
  }
  
  /*涟漪效果一个是背景渐变一个是圆圈渐变,而一个元素不能同时有两个动画*/
  .anim:after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    border-radius: 50%;
  }
  
  /*选中涟漪*/
  .checked .anim {
    animation: anim-in 0.75s;
  }
  
  .checked .anim:after {
    animation: anim-in-pseudo 0.75s;
  }
  /*取消涟漪*/
  .nochecked .anim {
    animation: anim-out 0.75s;
  }
  .nochecked .anim:after {
    animation: anim-out-pseudo 0.75s;
  }
  @keyframes anim-in {
    0% {
      width: 0%;
    }
    100% {
      width: 100%;
    }
  }
  @keyframes anim-in-pseudo {
    0% {
      background: rgba(0, 0, 0, 0.25);
    }
    100% {
      background: transparent;
    }
  }
  @keyframes anim-out {
    0% {
      width: 0%;
    }
    100% {
      width: 100%;
    }
  }
  @keyframes anim-out-pseudo {
    0% {
      background: rgba(0, 0, 0, 0.25);
    }
    100% {
      background: transparent;
    }
  }
</style>
